import { defineStore } from "pinia";
import { AccountType, UserInfoType } from "../types/user";
import { userLogin } from "../api/user";
// import { useRouter } from "vue-router";
// import router from "../router";
// let router = useRouter(); //此处的router等同于this.$router ,必须在组件的setup环境顶层调用
interface UserStateType {
  userInfo: UserInfoType | null;
  LOGINTIME: string | null;
}
// const router = useRouter()
export const useUser = defineStore("user", {
  state: (): UserStateType => ({
    userInfo: null,
    LOGINTIME: null,
  }),
  actions: {
    async loginAct(account: AccountType) {
      let res = await userLogin(account);
      this.userInfo = res.data;
      // router.push('/')
      // router.go(-1);
      // router.push("/mine");
    },
  },
  persist: {
    key: "userinfo-2302",
  },
});
